<?php
/**
 * ActivityController.php
 * 
 * @author: Cyw
 * @email: chenyunwen01@bianfeng.com
 * @created: 2014-1-26 上午11:28:58
 * @logs: 
 *       
 */
class ActivityController extends \BaseController {

    protected $layout = 'frontend._layout.base';

	/**
	 * Display the specified resource.
	 * 
     * 存在定制化信息
     *     分2类：
     *     一、静态资源根据需求改动，只改动css,js,img -----> 切换主题静态资源目录即可
     *     二、页面改动 -----> 切换主题静态资源目录、创建新Blade
	 * @param  int  $id 活动id
	 * @return Response
	 */
	public function show($id)
	{
	    
	    //定义
	    $blade = ''; // 模板切片存放地址
	    $theme = 'theme'; // 主题的根目录
	    $assetdirname = ''; // 主题静态资源目录 - 默认重构人员上传svn地址
	    
	    //获取活动
	    $activity = ActivityModel::find($id);
        $activity = is_object($activity) ? $activity->toArray() : $activity;
        
	    //获取活动模板
        $tpl = false;
        if (!empty($activity)) {
            
            //模板获取-根据活动配置
    	    $tpl = TemplateModel::find($activity['tid']);
    	    $tpl = is_object($tpl) ? $tpl->toArray() : $tpl;
    	    
    	    //模板切片-默认
    	    $blade = 'frontend.' . $theme . '.' . $tpl['dir_name'];
    	    $assetdirname = $tpl['dir_name'];
    	    
    	    //模板切片-是否定制化
            $customization_tpl = APP_PATH . '/views/frontend/theme_customization/' . $tpl['dir_name'] . '_' . $activity['id'] . '.blade.php';
            if (file_exists($customization_tpl)) {
                $theme = 'theme_customization';
                $assetdirname = $assetdirname . '_' . $activity['id'];
                $blade = 'frontend.' . $theme . '.' . $tpl['dir_name'] . '_' . $activity['id'];
            }
            
        } else {
            App::abort(404);
        }
        
	    $this->layout->content = View::make($blade)->with(compact('activity', 'tpl', 'theme', 'assetdirname'));
	}

}